package org.springblade.modules.admin.controller;

import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsResponseBody;
import com.sida.voice.service.VoiceTemplate;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.constant.VoiceConstant;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.utils.AsyncUtils;
import org.springblade.modules.admin.vo.VoiceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zcc
 * @version 1.0
 * @date 2023/4/15 10:35
 */
@Slf4j
@RestController
@RequestMapping("/admin/voice")
public class VoiceController {

	@Autowired
	private AsyncUtils asyncUtils;

	@PostMapping("sendPhone")
	@ApiOperation("发送语音播报")
	public R<Boolean> sendPhone(@RequestBody VoiceVo voiceVo) {
		Map<String, String> phoneMap = new HashMap<>(2);
		phoneMap.put("place", voiceVo.getPlace());
		if (voiceVo.getLocation() != null) {
			phoneMap.put("location", voiceVo.getLocation());
		}
		VoiceTemplate voiceTemplate = new VoiceTemplate();
		voiceTemplate.setTemplateCode(voiceVo.getTemplateCode());
		voiceTemplate.setTemplateParam(phoneMap);
		voiceTemplate.setPhoneNumber(voiceVo.getPhone());
		asyncUtils.sendPhone(voiceTemplate);
		return R.data(true);
	}

}
